﻿using System.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;



namespace BwanaBank.BankOnline.DAL
{
    public class CnData
    {
            
        private SqlConnection cn;

        public void Dispose()
        {
            if (cn != null)
            {
                cn.Dispose();
                cn = null;
            }
        }

        public void New()
        {
            cn = new SqlConnection("Data Source=(local);Initial Catalog=BWANABANQ;Integrated Security=True");
        }

        public bool Open()
        {
	        try {
		        if (cn.State == ConnectionState.Closed)
			        cn.Open();
		        return true;
	        } catch (Exception ex) {

                //MessageBox.Show("Erreur de fermeture de la base de données");
		        return false;
	        }
        }
         
            
        public bool Close()
        {
	        try {
		        if (cn.State == ConnectionState.Open)
			        cn.Close();
		        return true;
	        } catch (Exception ex) {
                //MessageBox.Show("Erreur de fermeture de la base de données");
		        return false;
	        }
        }

        public SqlConnection getCn()
        {
        return cn;
        }

        public bool connected()
        {
        if (cn.State == ConnectionState.Closed)
	        return false;
        return true;
        }

        public static void con_StateChange(object Sender, StateChangeEventArgs E)
        {
        Console.WriteLine("{0} - {1}", "ConnectionState", E.CurrentState.ToString());
        }


    }
}
